
/* eslint comma-dangle: "off" */
const path = require('path')
const getDevConf = require('./build/webpack.dev')
const merge = require('webpack-merge')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const ScriptPlugin = require('./build/script-plugin')
const argv = require('yargs').argv

let conf = {
  devServer: {
    // https://github.com/chimurai/http-proxy-middleware#http-proxy-options
    proxy: {
      '/mock': {
        target: `http://${require('./build/get-ip-adress')()}:3003`,
        pathRewrite: {
          '^/mock': ''
        },
        changeOrigin: true,
      },
      '/online': {
        // target: "http://192.168.1.110:8787",
        target: "http://192.168.1.197:8008",
        pathRewrite: {
          '^/online': ''
        },
        // changeOrigin: true,
        followRedirects: true,
        // cookieDomainRewrite: `
        // ASP.NET_SessionId=nwlyo2azpq3zhimw4vgz0fqo; .ASPXAUTH=6DC01C00B838F3E6D5B2A52EB5479111ABD6B3A9217F5374D84BBBB645575E282C75040448B19BC0D04ABB46FD05D0DDA644E86C0252FCDA08570BFC8B6F9A4BFFE00DCD86B6169008EC1145314EFC7A606A7A5649C5736701EF245433987AC6CE2E4156
        // `.trim(),
        headers: {
          // Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
          // Accept-Encoding: gzip, deflate
          // Accept-Language: zh-CN,zh;q=0.9,ja;q=0.8
          // Cache-Control: no-cache
          // Connection: keep-alive
          Cookie: 'ASP.NET_SessionId=khxnvfi2vxdpqt5ymqa3njjv; .ASPXAUTH=DEDCDE00573A5F976739371DA898DDE71B8C8BDF74AE63D5810D44D822B71E3EF69471D39845D47E181859276BC78C786CBD1A5BFD47308D1D4847CFDC483AE82F214766073E09ABBF56428A63FBBCB46A6EF7CAA058F87798984F92CF288B09B6410DE9',
          Host: '192.168.1.197:8008',
          Origin: 'http://192.168.1.197:8008',
          // Pragma: no-cache
          // Referer: 'http://192.168.1.197:8008/SchoolCulture/Index?id=0',
          'Upgrade-Insecure-Requests': 1,
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
        }
      }
    }
  },
  externals: {
    'vue': 'Vue'
    // 'vue-router': 'VueRouter'
  },
  plugins: [
    // new CopyWebpackPlugin([
    //   {
    //     from: path.resolve(__dirname, 'node_modules/vue-router/dist/vue-router.min.js'),
    //     to: path.resolve(outputPath, 'js/vue-router.min.js'),
    //   }
    // ]),
    // 添加指定的 cdn 包。或者指定路径的包也行
    new ScriptPlugin([
      'http://style.shenduxuetang.com/vue/2.5.22/vue.runtime.js',
      // 配合 copy-webpack-plugin 使用
      // 'js/vue-router.min.js',
    ]),
  ]

}
// 后端用来生成预览图用
if (argv['img']) {
  // let outputPath = path.resolve(__dirname, './dist/captrue-screen')
  conf = {
    entry: {
      main: './src/main-img/main.js'
    },
    // output: {
    //   path: outputPath,
    // },
    devServer: {
      contentBase: path.resolve(__dirname, './dist/captrue-screen'),
    }
  }
}

// 如果webpack配置有问题，需把 require('./build/friendly-error') 去掉才能看到错误
module.exports = require('./build/friendly-error')(
  merge(
    getDevConf({
      // dirname: __dirname, // 如果是子项目则需要传
      // splitCss: true,
    }),
    conf
  )
)
